import { useRoute } from 'vue-router';
import { ref ,onMounted} from 'vue';
import { getCategoryList } from '@/apis/category';
import { onBeforeRouteUpdate } from 'vue-router';
export  function useCategory() {
  const categoryList = ref({});
  const route = useRoute();
  
  const getCategory = async (id=route.params.id) => {
    const { data: { result } } = await getCategoryList(id);
    categoryList.value = result;
    console.log(categoryList.value);
  };
  onBeforeRouteUpdate((to) => {
    getCategory(to.params.id);
});
  onMounted(() => getCategory());
  return { categoryList };
}